#include<iostream>
using namespace std;

struct Student{
	string name;
	string banji;
	int grade;

};
Student S[100001];


int main(){

	freopen("input.txt","r",stdin);
	int n;
	cin>>n;
	int max_grade=0,min_grade=100;
	int max_i=-1,min_i=-1;
	for(int i=0;i<n;i++){
		cin>>S[i].name>>S[i].banji>>S[i].grade;
		if(S[i].grade>max_grade){
			max_grade=S[i].grade;
			max_i=i;
		}
		if(S[i].grade<min_grade){
			min_grade=S[i].grade;
			min_i=i;
		}
	}

	cout<<S[max_i].name<<" "<<S[max_i].banji<<endl;
	cout<<S[min_i].name<<" "<<S[min_i].banji<<endl;
	
}